#include <iostream>
#include "../result.hpp"
#include "../config.hpp"
#include "../drawer/drawer.hpp"
#include "../drawer/screen.hpp"
#include "../handler/handler.hpp"
#include "../object/world.hpp"
#include "../object/cube.hpp"
#include "../object/round.hpp"

extern "C" {
    #include "dll.hpp" // 替换为实际的C接口头文件名
}

void testRendering() {
    // 创建屏幕
    ScreenHandle screen = createScreen(800, 800);
    if (!screen) {
        std::cerr << "Failed to create screen!" << std::endl;
        return;
    }

    // 创建相机
    CameraHandle camera = createCamera();
    if (!camera) {
        std::cerr << "Failed to create camera!" << std::endl;
        destroyScreen(screen);
        return;
    }

    // 创建世界
    ColorWorldHandle world = createWorld(camera);
    if (!world) {
        std::cerr << "Failed to create world!" << std::endl;
        destroyCamera(camera);
        destroyScreen(screen);
        return;
    }

    // 创建立方体
    ColorCubeHandle cube = createCube(0, 0, -500, 100);
    if (!cube) {
        std::cerr << "Failed to create cube!" << std::endl;
        destroyWorld(world);
        destroyCamera(camera);
        destroyScreen(screen);
        return;
    }

    // 创建圆形
    // ColorRoundHandle round = createRound(200, 200, 50, 30.0f);
    // if (!round) {
    //     std::cerr << "Failed to create round!" << std::endl;
    //     destroyCube(cube);
    //     destroyWorld(world);
    //     destroyCamera(camera);
    //     destroyScreen(screen);
    //     return;
    // }

    // 将立方体和圆形添加到世界中
    addCubeToWorld(world, cube);
    //addRoundToWorld(world, round);

    // 启动渲染
    startRendering(screen, world);

    // 等待一段时间以观察渲染效果
    std::this_thread::sleep_for(std::chrono::seconds(5));

    // 清理资源
    //destroyRound(round);
    destroyCube(cube);
    destroyWorld(world);
    destroyCamera(camera);
    destroyScreen(screen);

    std::cout << "Rendering test completed." << std::endl;
}
